package com.cj.simple;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by JiangGe on 2016/9/11.
 */
public class CJImageView extends ImageView {

    private Bitmap src;
    private Bitmap dst;
    private Paint paint;

    public CJImageView(Context context) {
        this(context, null);
    }

    public CJImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CJImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        src = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        dst = BitmapFactory.decodeResource(getResources(), R.mipmap.circle);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.WHITE);

        canvas.drawBitmap(src, 0, 0, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(dst, 0, 0, paint);
    }
}
